package com.example.memo.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

public class MysqlOpenHelper extends SQLiteOpenHelper {
    //定义上下文对象
    public Context mcontext;
    //数据库版本号
    private static final int DATABASE_VERSION = 2;
    //数据库名称
    private static final String DATABASE_NAME = "memo.db";

    //创建表语句1
    public static final  String CREATE_NOTE="create table note_table ("+
            "id integer primary key autoincrement," +
            "bt text,"+
            "neirong text," +
            "create_time TIMESTAMP,"+
            "update_time TIMESTAMP,"+
             "img text,"+
            "fenglei text"+")";

    public static final  String CREATE_WAIT="create table wait_table ("+
            "id integer primary key autoincrement," +
            "neirong text," +
            "create_time TIMESTAMP,"+
            "update_time TIMESTAMP,"+
            "type int default 0"+")";


    public MysqlOpenHelper(@Nullable Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        this.mcontext=context;
    }




    //数据表初始化onCreate
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
      //通过execSQL（）执行SQL语句
        sqLiteDatabase.execSQL(CREATE_NOTE);
        sqLiteDatabase.execSQL(CREATE_WAIT);
        Toast.makeText(mcontext, "创建note表成功", Toast.LENGTH_SHORT).show();

    }
    // 作用：更新数据库表结构onUpgrade
    //调用这个类时new MysqlOpenHelper(context,"mydb",null,3);
    //传入sqlite版本号参数就可以自动触发onUpgrade
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    }









}
